<template>
	<view class="page">
		<view style="height: 20rpx;"></view>
		<view class="block" v-for="(item,i) in list" :key="i">
			<view class="time">
				{{item.hour}}
			</view>
			<view style="display: flex;align-items: center;">
				<view class="content" :style="{color:getEmoObj(item.emotion_index,'emotion').color}">
					{{getEmoObj(item.emotion_index,'emotion').title}}</view>
				<image class="img" :src="getEmoObj(item.emotion_index,'emotion').icon"></image>
				<view class="content" :style="{color:getEmoObj(item.stress_index,'stress').color}">
					{{getEmoObj(item.stress_index,'stress').title}}</view>
				<image class="img" :src="getEmoObj(item.stress_index,'stress').icon"></image>
				<view class="content" :style="{color:getEmoObj(item.tired_index,'tired').color}">
					{{getEmoObj(item.tired_index,'tired').title}}</view>
				<image class="img" :src="getEmoObj(item.tired_index,'tired').icon"></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'
	export default {
		computed: {
			...mapState(['member']),
		},
		data() {
			return {
				list: [],
				pageNum:1,
				pageSize:20,
				pageCount:0
			};
		},
		onLoad() {
			this.getData();
		},
		onReachBottom() {
			if(this.pageCount&&this.pageNum<this.pageCount){
				this.pageNum+=1;
				this.getData()
			}
		},
		methods: {
			getData(){
				uni.$u.http.post('/client/history_identifys', {
					imei: this.member.imei,pageNum:this.pageNum,pageSize:this.pageSize
				}).then(res => {
					let count = res.data.historyCount[0].count;
					this.pageCount = Math.ceil(count/this.pageSize)
					for (let i in res.data.identify_all) {
						let emo = res.data.identify_all[i];
						emo.tired_index = 100 - emo.tired_index;
						this.list.push(emo)
					}
				})
			},
			getEmoObj(index, type) {
				//1 心情 2 压力 3 疲劳
				if (index <= 49) {
					if (type == 'emotion') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/3.png',
							color: '#FF0036',
							title: '心情一般'
						}
					}
					if (type == 'stress') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/1.png',
							color: '#55CF04',
							title: '较为松弛'
						}
					}
					return {
						icon: 'https://baxztech.com/bian_admin_api/public/bianmp/3.png',
						color: '#FF0036',
						title: '略有疲惫',
					}
				} else if (index >= 50 && index <= 69) {
					if (type == 'emotion') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/2.png',
							color: '#01D6D6',
							title: '心情平和'
						}
					}
					if (type == 'stress') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/2.png',
							color: '#01D6D6',
							title: '稍有压力'
						}
					}
					if (type == 'tired') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/2.png',
							color: '#01D6D6',
							title: '精力适中'
						}
					}
				} else if (index >= 70) {
					if (type == 'emotion') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/1.png',
							color: '#55CF04',
							title: '比较愉悦'
						}
					}
					if (type == 'stress') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/3.png',
							color: '#FF0036',
							title: '有压力',
						}
					}
					if (type == 'tired') {
						return {
							icon: 'https://baxztech.com/bian_admin_api/public/bianmp/1.png',
							color: '#55CF04',
							title: '精力充沛'
						}
					}
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.time {
		height: 76rpx;
		line-height: 76rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
	}

	.block {
		margin-bottom: 30rpx;
	}

	.img {
		width: 48rpx;
		height: 48rpx;
		margin-right: 48rpx;
	}

	.content {
		margin-right: 10rpx;
		height: 48rpx;
		line-height: 48rpx;
		font-size: 28rpx;
		font-weight: 400;
	}
</style>